package com.xja.controller;/**
 * @className: CourseController
 * @description: TODO 类描述
 * @author: wkx
 * @date: 2022/4/19
 **/

import com.xja.pojo.BlogUsers;
import com.xja.pojo.CourseInfo;
import com.xja.service.CourseService;
import org.apache.dubbo.config.annotation.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @ClassName : CourseController  //类名

 * @Author : Lenovo //作者
 * @Date: 2022/4/19  16:54
 */
@Controller
@RequestMapping("course")
public class CourseController {
    private Logger logger = LoggerFactory.getLogger(ArticleController.class);
    @Reference(url = "dubbo://localhost:20882")
    private CourseService courseService;

    @RequestMapping("getCourse")
    public String getCourse(Model model, @RequestParam(value = "page",defaultValue = "1") Integer page, CourseInfo course){
        logger.info("获取课程列表");

        List<CourseInfo> courseList = courseService.getCourse(page, course);

        model.addAttribute("courseList",courseList);
        model.addAttribute("c",course);
        return "course";
    }
    @RequestMapping("start")
    public String start(Integer cid){
        logger.info("开课");
        courseService.startCourse(cid);

        return "redirect:/course/getCourse";
    }

    @RequestMapping("stop")
    public String stop(Integer cid){
        logger.info("停课");
        courseService.stopCourse(cid);
        return "redirect:/course/getCourse";
    }

    @RequestMapping("toAddCourse")
    public String toAddCourse(){
        logger.info("跳转到添加课程");

        return "addCourse";
    }
    @RequestMapping("addCourse")
    public String toAddCourse(CourseInfo course){
        logger.info("添加课程");
        courseService.addCourse(course);
        return "redirect:/course/getCourse";
    }
    @RequestMapping("getCoursePerson")
    public String getCoursePerson(Model model, @RequestParam(value = "page",defaultValue = "1") Integer page, Integer cid){
        logger.info("获取选课用户列表");

        List<BlogUsers> blogUsers = courseService.getCoursePerson(cid);

        model.addAttribute("blogUsersList",blogUsers);

        return "course_user";
    }

}
